package com.xj.api.bussiness.billOfDocumentImg.web;

import com.xj.api.bussiness.billOfDocumentImg.service.ITbBillOfDocumentImgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.xj.api.base.web.BaseController;
import com.xj.common.base.common.bean.AbstractBean;
import com.xj.common.bussiness.billOfDocumentImg.entity.TbBillOfDocumentImg;
import io.swagger.annotations.ApiOperation;

import java.util.List;

/**
 * <p>
 * 单据（合同、发票、设备档案）的照片和编号表  前端控制器
 * </p>
 *
 * @author Hmemb
 * @since 2018-01-27
 */
@RestController
@RequestMapping("billOfDocumentImg")
public class TbBillOfDocumentImgController extends BaseController{
	
	@Autowired
	private ITbBillOfDocumentImgService billOfDocumentImgService;
	
	@GetMapping
	@ApiOperation(value = "  列表", httpMethod = "GET", notes = "  列表")
	public AbstractBean billOfDocumentImgList(@RequestParam(required=false,defaultValue="0") Integer pageNum,@RequestParam(required=false,defaultValue="10") Integer pageSize){
		return json(billOfDocumentImgService.selectMapsPage(new Page<TbBillOfDocumentImg>(pageNum, pageSize), new EntityWrapper<TbBillOfDocumentImg>()));
	}
	
	@GetMapping("/{id}.auth")
	@ApiOperation(value = "  詳情", httpMethod = "GET", notes = "  詳情")
	public AbstractBean billOfDocumentImgContent(@PathVariable Integer id){
		return json(billOfDocumentImgService.selectById(id));
	}
	
	@PostMapping("save")
	@ApiOperation(value = "  新增", httpMethod = "POST", notes = " 新增")
	public AbstractBean add(TbBillOfDocumentImg tbbillofdocumentimg){
		if(!billOfDocumentImgService.insertOrUpdate(tbbillofdocumentimg)){
		return error();
	    }
		return success();
	}
	@DeleteMapping("{id}/delete")
	@ApiOperation(value = "  删除", httpMethod = "POST", notes = " 删除")
    public AbstractBean delete(@PathVariable(required=true) Integer id) {	
		if(!billOfDocumentImgService.deleteById(id)){
		return error();
		}
		return success();
    }
    @PostMapping("getBillOfDocumentByCondition")
	@ApiOperation(value = "根据设备id,身份证号,大架号查询单据（合同、发票、设备档案）的照片和编号表",httpMethod = "POST",notes = "根据设备id,身份证号,大架号查询单据（合同、发票、设备档案）的照片和编号表")
	public AbstractBean getBillOfDocumentByCondition(TbBillOfDocumentImg tbBillOfDocumentImg){
		List<TbBillOfDocumentImg> list = billOfDocumentImgService.getBillOfDocumentByCondition(tbBillOfDocumentImg);
		if (list != null && list.size()>0){
			return SuccessMessage("用户存在","1");
		}else {
			return  fail("用户不存在","0");
		}
	}
}
